package test;

import entity.Personnel;
import entity.TableDTO;
import util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class SearchTable {
    public static void main(String[] args) {
        StringBuilder sql = new StringBuilder();
        sql.append("select * from personnel;");
        Connection connection = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        List<Personnel> dataList = new ArrayList<>();
        try{
            connection=DBUtil.getConn();
            ps=connection.prepareStatement(sql.toString());
            rs=ps.executeQuery();
            while (rs.next()) {
                Personnel personnel=new Personnel();
                personnel = new Personnel();
                personnel.setPersonnelID(rs.getInt("PersonnelID"));
                personnel.setFullName(rs.getString("FullName"));
                personnel.setGender(rs.getString("Gender"));
                personnel.setEthnicity(rs.getString("Ethnicity"));
                personnel.setDepartmentID(rs.getInt("DepartmentID"));
                personnel.setTitle(rs.getString("Title"));
                personnel.setBirthDate(rs.getDate("BirthDate"));
                personnel.setEducationLevel(rs.getString("EducationLevel"));
                personnel.setBaseSalary(rs.getDouble("BaseSalary"));
                personnel.setPositionSalary(rs.getDouble("PositionSalary"));
                personnel.setPositionAllowance(rs.getDouble("PositionAllowance"));
                personnel.setHireDate(rs.getDate("HireDate"));

                dataList.add(personnel);
            }
            for (Personnel personnel : dataList) {
                System.out.println("Personnel ID: " + personnel.getPersonnelID());
                System.out.println("Full Name: " + personnel.getFullName());
                System.out.println("Gender: " + personnel.getGender());
                System.out.println("Ethnicity: " + personnel.getEthnicity());
                System.out.println("Department ID: " + personnel.getDepartmentID());
                System.out.println("Title: " + personnel.getTitle());
                System.out.println("Birth Date: " + personnel.getBirthDate());
                System.out.println("Education Level: " + personnel.getEducationLevel());
                System.out.println("Base Salary: " + personnel.getBaseSalary());
                System.out.println("Position Salary: " + personnel.getPositionSalary());
                System.out.println("Position Allowance: " + personnel.getPositionAllowance());
                System.out.println("Hire Date: " + personnel.getHireDate());
                System.out.println("---------------------");
            }


        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DBUtil.closeRs(rs);
            DBUtil.closePS(ps);
            DBUtil.closeConn(connection);
        }


    }
}
